<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>考试管理</title>
    <meta name="keywords" content="">
    <link href="../static/resources/bootstrap/css/bootstrap.css" rel="stylesheet">
    <link href="../static/resources/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link href="../static/resources/css/style.css" rel="stylesheet">
    <link href="../static/resources/layui/css/layui.css" rel="stylesheet">
    <link href="../static/resources/css/exam.css" rel="stylesheet">
    <!-- Javascript files -->
    <!-- jQuery -->
    <script type="text/javascript" src="../static/resources/js/jquery/jquery-3.1.1.min.js"></script>
    <!-- Bootstrap JS -->
    <script type="text/javascript" src="../static/resources/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../static/resources/layui/layui.all.js"></script>
</head>
<body>
<div class="container">
    <div class="page-content">
        <form id="form-examp-add">
            <input type="hidden" value="${map.exam.id}" name="id" id="examId">
            <div class="form-line add-update-examname">
                <span class="form-label"><span class="warning-label">*</span>考试名称：</span>
                <input id="examName" type="text" class="df-input-narrow" name="examName" value="${map.exam.examName}">
                <span class="form-message"></span>
            </div>
            <div class="form-line add-update-exam-type">
                <span class="form-label"><span class="warning-label">*</span>考试类型：</span>
                <input type="hidden" value="${map.exam.examType}" id="type">
                <select class="df-input-narrow" name="examType" id="examType">
                    <option value="1">公开考试</option>
                    <option value="2">私有考试</option>
                </select>
                <span class="form-message"></span>
            </div>
            <div class="form-line add-update-exam-paper">
                <span class="form-label"><span class="warning-label">*</span>选择试卷：</span>

                <input type="text" value="${map.exam.examPaper.id}" id="examPaperId" hidden>
                <input type="text" placeholder="请选择点击试卷" id="selectExamPaper" readonly value="${map.exam.examPaper.name}">

                <span class="form-message"></span>
            </div>
            <div class="form-line add-update-exam-paper">
                <span class="form-label"><span class="warning-label">*</span>考试简介：</span><textarea
                    style="resize: none;width: 300px;height: 200px" placeholder="考试简介"
                    name="examIntro" id="examIntro">${map.exam.examIntro}</textarea>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <label class="layui-form-label"><span
                            class="warning-label">*</span>请选择考试开始时间:&nbsp;&nbsp;</label><input
                        class="layui-input" id="startTime" placeholder="点击选择考试开始时间" type="text" name="startTime" value="${map.start}">
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <label class="layui-form-label"><span
                            class="warning-label">*</span>请选择考试截止时间:&nbsp;&nbsp;</label><input
                        class="layui-input" id="endTime" placeholder="点击选择考试结束时间" type="text" name="endTime" value="${map.end}">
                </div>
            </div>
            <div class="form-line">
                <input value="确认修改" type="button" id="subBtn" class="df-submit btn btn-info">
                <input value="取消" type="button" id="cancelBtn" class="df-submit btn btn-danger">
            </div>
        </form>
    </div>
</div>
</body>
</html>
<script>
    $(function () {

        //时间选择
        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //日期时间选择器
            laydate.render({
                elem: '#startTime'
                , type: 'datetime'
            });
        })

        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //日期时间选择器
            laydate.render({
                elem: '#endTime'
                , type: 'datetime'
            });
        })

    });

    //弹出遮罩层 郭瀚钰
    $("#selectExamPaper").click(function () {
        layer.open({
            type: 2,
            title: '选择试卷',
            fix: false,
            maxmin: true,
            shadeClose: true,
            area: ['1100px', '600px'],
            content: '/view/find-examPaper.html',
            end: function () {
            }
        })
    });

    function check() {
        return $("#addUserForm").validate({
            rules: {
                name: {
                    required: true
                },
                password: {
                    required: true
                }
            },
            message: {
                name: {
                    required: ""
                },
                password: {
                    required: ""
                }
            }
        })
    }

    $("#subBtn").click(function () {
        $.ajax({
            type:"POST",
            url:"/ExamAddExam",
            data:{
                id: $("#examId").val(),
                examName: $("#examName").val(),
                examType: $("#examType").val(),
                examPaperId: $("#examPaperId").val(),
                examIntro: $("#examIntro").val(),
                startTime: $("#startTime").val(),
                endTime: $("#endTime").val()
            },
            success:function (data) {
                if(data > 0){
                    $("#cancelBtn").click();
                }
            }
        });
    });

    $("#cancelBtn").click(function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.getAllExamByPage();
        parent.layer.close(index);
    });

    var chooseType = function () {
        var v = $("#type").val();
        $("#examType [value = "+v+"]").attr("selected", true);
    }

    chooseType();
</script>